package com.example.demo.controller;

import com.example.demo.entity.user;
import com.example.demo.mapper.usermapper;
import com.example.demo.service.userserviceInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class usercontroller {
    @Autowired
    userserviceInterface userdao;
    @Autowired
    usermapper usermapper;

    @RequestMapping("/login")
    public int login(user u) {
        int bool = 0;

        u = userdao.login(u);
        
        if (u != null) {
            bool = 1;
        }

        System.out.println(u);
        return bool;

    }

    @RequestMapping("/signup")
    public int signup(user u) {
        return userdao.signup(u);
    }

    @RequestMapping("/checkusername")
    public int checkusername(user u) {
        int bool = 0;

        u = userdao.checkusername(u);

        if (u == null) {
            bool = 1;
        }

        return bool;

    }

    @RequestMapping("/checkuser")
    public int checkuser(user u) {
        int bool = 0;
        String realname, phonenum, userid;

        realname = u.getRealname();
        phonenum = u.getPhonenum();
        userid = u.getUserid();

        //System.out.println(realname + phonenum + userid);

        u = userdao.checkuser(u);

        //System.out.println(u.getRealname()+u.getPhonenum()+u.getUserid());

        if (u != null) {
            if (realname.equals(u.getRealname()) && phonenum.equals(u.getPhonenum()) && userid.equals(u.getUserid())) {
                bool = 1;
            }
        }

        return bool;
    }

    @RequestMapping("/resetpass")
    public int resetpass(user u) {
        return userdao.resetpass(u);
    }

    @RequestMapping("/updata")
    public int updata(user u) {
        return userdao.updata(u);
    }
}
